<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TodoList案例</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="box">
        <!-- <input type="text" @input="handleInput"> -->
        <input type="text" v-model="mytext">
        <button @click="handleAdd">添加</button>
        <ul>
            <li v-for="(item, index) in todoList" :key="item">
                {{item}}
                <button @click="handleDelete(index)">删除</button>
            </li>
        </ul>
        <!-- v-if或者v-show都行 -->
        <div v-if="todoList.length===0">暂无内容</div>
    </div>
    <script>

        const obj = {
            data() {
                return {
                    mytext: "",
                    todoList: [11, 22, 33]
                }
            },

            methods: {
                // handleInput(evt) {
                //     console.log(evt.target.value);
                // },
                handleAdd() {
                    //排除空的情况
                    if (this.mytext) {
                        this.todoList.push(this.mytext)
                        //清空输入框
                        this.mytext = ""
                    }
                },
                handleDelete(index) {
                    this.todoList.splice(index, 1)
                    console.log(index);
                }
            }
        }
        Vue.createApp(obj).mount("#box");
    </script>

</body>

</html>